package top.yehot.cmmu.shiro.util;

import java.util.Objects;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.BeanUtils;

import top.yehot.cmmu.shiro.models.dto.LoginUserDTO;

/**
 * shiro 工具类
 * 
 * @author lquan
 * @date 2022-10-16 19:43:19
 */
public class ShiroUtil {
	
	public static Subject getSubject() {
        return SecurityUtils.getSubject();
    }
	
	public static LoginUserDTO getLoginUser() {
		Object obj = getSubject().getPrincipal();
		
		LoginUserDTO user = null;
        if (Objects.nonNull(obj)) {
            user = new LoginUserDTO();
            BeanUtils.copyProperties(obj, user);
        }
        return user;
    }

}
